def count_remaining_trees():
    l, m = map(int, input().split())
    trees = set(range(l + 1))
    for _ in range(m):
        u, v = map(int, input().split())
        trees -= set(range(u, v + 1))
    print(len(trees))

count_remaining_trees()